package away3d.cameras.lenses
{
import away3d.core.math.Matrix3DUtils ;

/**
 * The PerspectiveLens object provides a projection matrix that projects 3D geometry isometrically. This entails
 * there is no perspective distortion, and lines that are parallel in the scene will remain parallel on the screen.
 */
class OrthographicLens extends LensBase
{
    
    
    private var _projectionHeight : Float ;
    
    
    
    /**
     * Creates a new OrthogonalLens object.
     * @param fieldOfView The vertical field of view of the projection.
     */
    public function new( projectionHeight : Float = 500 )
    {
        
        super() ;
        _projectionHeight = projectionHeight ;
        
    }
    
    
    public var projectionHeight( get_projectionHeight, set_projectionHeight ) : Float ;
    
    
    /**
     * The vertical field of view of the projection.
     */
    private function get_projectionHeight() : Float
    {
        
        return _projectionHeight ;
        
    }
    
    
    private function set_projectionHeight( value : Float ) : Float
    {
        
        if( value == _projectionHeight ) return value ;
        _projectionHeight = value ;
        invalidateMatrix() ;
        return value ;
        
    }
    
    
    /**
     * @inheritDoc
     */
    override private function updateMatrix()
    {
        
        var raw     = Matrix3DUtils.RAW_DATA_CONTAINER ;
        var maxY    = _projectionHeight*.5 ;
        var maxX    = maxY*_aspectRatio ;
        
        // assume symmetric frustum
        raw[ 0  ] = 2/( _projectionHeight*_aspectRatio ) ;
        raw[ 5  ] = 2/_projectionHeight ;
        raw[ 10 ] = 1/( _far-_near ) ;
        raw[ 14 ] = _near/( _near-_far ) ;
        raw[ 1  ] = raw[ 2  ] = raw[ 3  ] = raw[ 4 ] =
        raw[ 6  ] = raw[ 7  ] = raw[ 8  ] = raw[ 9 ] =
        raw[ 11 ] = raw[ 12 ] = raw[ 13 ] = 0 ;
        raw[ 15 ] = 1 ;
        
        _frustumCorners[0] = _frustumCorners[9] = _frustumCorners[12] = _frustumCorners[21] = -maxX ;
        _frustumCorners[3] = _frustumCorners[6] = _frustumCorners[15] = _frustumCorners[18] = maxX ;
        _frustumCorners[1] = _frustumCorners[4] = _frustumCorners[13] = _frustumCorners[16] = -maxY ;
        _frustumCorners[7] = _frustumCorners[10] = _frustumCorners[19] = _frustumCorners[22] = maxY ;
        _frustumCorners[2] = _frustumCorners[5] = _frustumCorners[8] = _frustumCorners[11] = _near ;
        _frustumCorners[14] = _frustumCorners[17] = _frustumCorners[20] = _frustumCorners[23] = _far ;
        
        _matrix.copyRawDataFrom( raw ) ;
        
    }
    
    
}